package com.iogogogo.supervisord4j.pojo.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.common.base.Objects;
import com.iogogogo.supervisord.domain.SupervisordProcess;
import com.iogogogo.supervisord4j.util.Java8DateTimeUtils;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.time.LocalDateTime;

/**
 * Created by tao.zeng on 2021/7/7.
 */
@Data
@Entity
@Table(name = "supervisord_job")
public class JobEntity extends SupervisordProcess {

    @Id
    @Column(name = "job_id")
    private Long jobId;

    @Column(name = "instance")
    private String instance;

    @Column(name = "server")
    private String server;

    @Column(name = "name")
    private String name;

    @Column(name = "source")
    private String source;

    @Column(name = "sink")
    private String sink;

    @Column(name = "remark")
    private String remark;

    @Column(name = "create_time")
    @JsonFormat(pattern = Java8DateTimeUtils.PATTERN_YYYY_MM_DD_HH_MM_SS)
    private LocalDateTime createTime;

    @Column(name = "update_time")
    @JsonFormat(pattern = Java8DateTimeUtils.PATTERN_YYYY_MM_DD_HH_MM_SS)
    private LocalDateTime updateTime;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        JobEntity entity = (JobEntity) o;
        return Objects.equal(instance, entity.instance) && Objects.equal(server, entity.server) && Objects.equal(name, entity.name);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(super.hashCode(), instance, server, name);
    }
}
